package org.windowkit.toolkit.widget.list;

import javax.swing.JList;
import javax.swing.ListModel;

import org.ddevil.data.Data;
import org.ddevil.data.set.DataSet;


/**
 * JList extension.
 * Where Do I Begin.
 *
 * @author Rich
 */
public class ListPane<T extends Data> extends JList {
	private static final long serialVersionUID = -1992038409345770036L;


	public ListPane(final DateSetListModel<T> model){
        super(model);
    }
    public ListPane() {
        this(new DateSetListModel<T>());
    }

    @Override
    public void setModel(final ListModel model) {
        if(model instanceof DateSetListModel){
            super.setModel(model);
        }else{
            throw new IllegalArgumentException("ListPane must use DateSetListModel.");
        }
    }

    @Override
    public DateSetListModel<T> getModel() {
        return (DateSetListModel<T>)super.getModel();
    }

    public void setDataSet(final DataSet<T> data){
        getModel().setDataSet(data);
    }

    public void setMainAttribute(final String attrib){
        getModel().setMainAttribute(attrib);
    }

    public T getSelectedRecord(){
        T ret = null;
        int sel = getSelectedIndex();
        if(sel > -1){
        	// TODO make sure this is right, i just through it in ya know
            ret = getModel().getRecordAt(sel);
        }
        return ret;
    }

    /**
     * Clears the selection in the list.
     */
    public void clearValue() {
        clearSelection();
    }

}
